#include "CPetConfig.h"

int CPetConfig::Init()
{
    _astPetLevelConfigs.m_iUsedCount = MAX_PET_LEVEL_CONFIG;
    _astPetStarConfigs.m_iUsedCount = MAX_PET_STAR_CONFIG;
    _astPetExploreConfigs.m_iUsedCount = MAX_EXPLORE_CONFIG_NUM;
    _iMaxExploreEventCounts = -1;

    for (int i = 0; i < _astPetLevelConfigs.Size(); ++i)
    {
        _astPetLevelConfigs[i].Clear();
    }

    for (int i = 0; i < _astPetStarConfigs.Size(); ++i)
    {
        _astPetStarConfigs[i].Clear();
    }

    for (int i = 0; i < _astPetExploreConfigs.Size(); ++i)
    {
        _astPetExploreConfigs[i].Clear();
    }

    return 0;
}

int CPetConfig::AddPetLevelConfig(CPetLevelConfigData& stData)
{
    if (!stData.HasConfig())
    {
        return ERROR_PET_LEVEL_ADD_EMPTY_CONFIG;
    }

    if( stData._iPetLevel>=_astPetLevelConfigs.GetCount() )
    {
        return ERROR_PET_LEVEL_ID;
    }

    if (_astPetLevelConfigs[stData._iPetLevel].HasConfig())
    {
        return ERROR_PET_LEVEL_DUPLICATED_CONFIG;
    }

    _astPetLevelConfigs[stData._iPetLevel] = stData;

    return 0;
}

int CPetConfig::AddPetExploreConfig( CPetExploreConfigData & stData)
{
    if (!stData.HasConfig())
    {
        return ERROR_PET_EXPLORE_EMPTY_CONFIG;
    }

    if( stData._iExploreId>=_astPetExploreConfigs.GetCount() )
    {
        return ERROR_PET_EXPLORE_ID;
    }

    if (_astPetExploreConfigs[stData._iExploreId].HasConfig())
    {
        return ERROR_PET_EXPLORE_DUPLICATED_CONFIG;
    }

    _astPetExploreConfigs[stData._iExploreId] = stData;

    return 0;
}

int CPetConfig::AddPetStarConfig( CPetStarConfigData& stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_PET_STAR_ADD_EMPTY_CONFIG;
    }

    int iLevelStar = stData._iPetLevel*MAX_PET_LEVEL_CONFIG + stData._iPetStar;
    if( iLevelStar>=_astPetStarConfigs.GetCount() )
    {
        return ERROR_PET_LEVEL_STAR_CONFIG;
    }

    if (_astPetStarConfigs[iLevelStar].HasConfig())
    {
        return ERROR_PET_STAR_DUPLICATED_CONFIG;
    }

    _astPetStarConfigs[iLevelStar] = stData;

    return 0;
}

int CPetConfig::GetPetExploreConfigCounts()
{
    if( _iMaxExploreEventCounts>0 )
    {
        return _iMaxExploreEventCounts;
    }

    _iMaxExploreEventCounts = 0;
    for( int i=0; i<_astPetExploreConfigs.Size(); ++i )
    {
        if( _astPetExploreConfigs[i]._bHasConfig )
        {
            _iMaxExploreEventCounts++;
        }
    }

    return _iMaxExploreEventCounts; 
}

int CPetConfig::GetPetExploreConfig(int iExploreId, CPetExploreConfigData& stData)
{
    if( iExploreId>= _astPetExploreConfigs.GetCount() )
    {
        return ERROR_PET_EXPLORE_ID;
    }

    if( !_astPetExploreConfigs[iExploreId]._bHasConfig )
    {
        return ERROR_PET_EXPLORE_ID;
    }

    stData = _astPetExploreConfigs[iExploreId];

    return 0;
}

int CPetConfig::GetPetStarConfig(int iPetLevel, int iPetStar, CPetStarConfigData& stData)
{
    if( iPetLevel>MAX_PET_LEVEL_CONFIG )
    {
        return ERROR_PET_LEVEL_ID;
    }

    if( iPetStar>=MAX_PET_STAR )
    {
        iPetStar = MAX_PET_STAR-1;
    }

    int iLevelStar = iPetLevel*MAX_PET_LEVEL_CONFIG + iPetStar;
    if( iLevelStar >= _astPetStarConfigs.GetCount() )
    {
        return ERROR_PET_LEVEL_STAR_ID;
    }

    if( !_astPetStarConfigs[iLevelStar]._bHasConfig )
    {
        return ERROR_PET_LEVEL_STAR_ID;
    }

    stData = _astPetStarConfigs[iLevelStar];

    return 0;
}

int CPetConfig::GetPetLevelConfig(int iPetLevel, CPetLevelConfigData& stData)
{
    if( iPetLevel >= _astPetLevelConfigs.GetCount() )
    {
        return ERROR_PET_LEVEL_ID;
    }

    if( !_astPetLevelConfigs[iPetLevel]._bHasConfig )
    {
        return ERROR_PET_LEVEL_ID;
    }

    stData = _astPetLevelConfigs[iPetLevel];

    return 0;
}

int CPetConfig::AddExploreCDtimeConfig( CExploreCDTimeConfigData& stData)
{
    if (!stData.HasConfig())
    {
        return ERROR_PET_EXPLORE_EMPTY_CONFIG;
    }

    if( stData._iExploreId>=_astPetExploreCDTimesConfigs.GetCount() )
    {
        return ERROR_PET_EXPLORE_ID;
    }

    if (_astPetExploreCDTimesConfigs[stData._iExploreId].HasConfig())
    {
        return ERROR_PET_EXPLORE_DUPLICATED_CONFIG;
    }

    _astPetExploreCDTimesConfigs[stData._iExploreId] = stData;

    return 0;
}

int CPetConfig::GetExploreCDTimeConfig(int iExploreId, CExploreCDTimeConfigData& stData)
{
    if( iExploreId>= _astPetExploreCDTimesConfigs.GetCount() )
    {
        return ERROR_PET_EXPLORE_ID;
    }

    if( !_astPetExploreCDTimesConfigs[iExploreId]._bHasConfig )
    {
        return ERROR_PET_EXPLORE_ID;
    }

    stData = _astPetExploreCDTimesConfigs[iExploreId];

    return 0;
}

